/*
 * Copyright (c) 2009 Frederic Daoud
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.stripesbook.rayures.view.stripes;

import javax.servlet.jsp.JspException;
import net.sourceforge.stripes.tag.HtmlTagSupport;

/**
 * Corresponds to {@link HtmlTagSupport}.
 *
 * @author Frederic Daoud
 */
public abstract class STagSupport<T extends HtmlTagSupport, V extends STagSupport<?, ?>>
  extends SStripesTagSupport<T, V>
{
  public STagSupport(T tag) {
    super(tag);
  }

  public V attr(String name, String value) {
    try {
      getTag().setDynamicAttribute(null, name, value);
      return getThis();
    }
    catch (JspException exc) {
      throw new RuntimeException("Could not set attribute " + name + " to " + value, exc);
    }
  }

  public V id(String id) { return attr("id", id); }
  public V cssClass(String cssClass) { return attr("class", cssClass); }
  public V title(String title) { return attr("title", title); }
  public V style(String style) { return attr("style", style); }
  public V dir(String dir) { return attr("dir", dir); }
  public V lang(String lang) { return attr("lang", lang); }
  public V tabindex(int tabindex) { return attr("tabindex", String.valueOf(tabindex)); }
  public V accesskey(char accesskey) { return attr("accesskey", String.valueOf(accesskey)); }
  public V onfocus(String onfocus) { return attr("onfocus", onfocus); }
  public V onblur(String onblur) { return attr("onblur", onblur); }
  public V onselect(String onselect) { return attr("onselect", onselect); }
  public V onchange(String onchange) { return attr("onchange", onchange); }
  public V onclick(String onclick) { return attr("onclick", onclick); }
  public V ondblclick(String ondblclick) { return attr("ondblclick", ondblclick); }
  public V onmousedown(String onmousedown) { return attr("onmousedown", onmousedown); }
  public V onmouseup(String onmouseup) { return attr("onmouseup", onmouseup); }
  public V onmouseover(String onmouseover) { return attr("onmouseover", onmouseover); }
  public V onmousemove(String onmousemove) { return attr("onmousemove", onmousemove); }
  public V onmouseout(String onmouseout) { return attr("onmouseout", onmouseout); }
  public V onkeypress(String onkeypress) { return attr("onkeypress", onkeypress); }
  public V onkeydown(String onkeydown) { return attr("onkeydown", onkeydown); }
  public V onkeyup(String onkeyup) { return attr("onkeyup", onkeyup); }

}
